<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script type="module">
            import axios from './axios.js'
            let promise = axios
                .get('hd.php')
                .then(goods => {
                    let item = goods.sort(order('price', 'desc'))[0]
                    //获取评论,返回了一个Promise
                    return axios.get(`comment.php?id=${item.id}`)
                })
                .then(comments => {
                    console.log(comments)
                })
                .catch(error => {
                    console.log(error)
                })

            //处理排序
            function order(field, type) {
                return (a, b) => {
                    switch (type) {
                        case 'asc':
                            return a[field] - b[field]
                            break
                        case 'desc':
                            return b[field] - a[field]
                    }
                }
            }
        </script>
    </body>
</html>
